{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "7b80af65-0328-4de2-b38d-ec07d765bb57",
   "metadata": {
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:39.854125Z",
     "end_time": "2024-02-07T17:08:40.746664Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": "\"Output #1: I'm excited to learn Python.\""
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"Output #1: I'm excited to learn Python.\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "outputs": [
    {
     "data": {
      "text/plain": "'Output 2#: Four plus five equals 9.'"
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 两个数值相加\n",
    "x = 4\n",
    "y = 5\n",
    "z = x + y\n",
    "'Output 2#: Four plus five equals {0:d}.'.format(z)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:39.857634Z",
     "end_time": "2024-02-07T17:08:40.746664Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "outputs": [
    {
     "data": {
      "text/plain": "\"Output #3: [1, 2, 3, 4], ['first', 'second', 'third', 'fourth'], [1, 2, 3, 4, 'first', 'second', 'third', 'fourth']\""
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 两个列报表相加\n",
    "a = [1, 2, 3, 4]\n",
    "b = ['first', 'second', 'third', 'fourth']\n",
    "c = a + b\n",
    "'Output #3: {0}, {1}, {2}'.format(a, b, c)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:39.864877Z",
     "end_time": "2024-02-07T17:08:40.747664Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "outputs": [
    {
     "data": {
      "text/plain": "'Output #4: 9'"
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x = 9\n",
    "'Output #4: {0}'.format(x)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:39.869559Z",
     "end_time": "2024-02-07T17:08:40.747664Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "outputs": [
    {
     "data": {
      "text/plain": "'Output #5: 81'"
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'Output #5: {0}'.format(3 ** 4)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:39.877155Z",
     "end_time": "2024-02-07T17:08:40.747664Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "outputs": [
    {
     "data": {
      "text/plain": "'Output #6: 4.0'"
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'Output #6: {0}'.format(int(8.3) / int(2.7))"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:39.882158Z",
     "end_time": "2024-02-07T17:08:40.747664Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "outputs": [
    {
     "data": {
      "text/plain": "'Output #7: 3.074'"
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'Output #7: {0:.3f}'.format(8.3 / 2.7)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:39.888658Z",
     "end_time": "2024-02-07T17:08:40.747664Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "outputs": [
    {
     "data": {
      "text/plain": "'Output #8: 12.0'"
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "y = 2.5 * 4.8\n",
    "'Output #8: {0:.1f}'.format(y)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:39.895166Z",
     "end_time": "2024-02-07T17:08:40.747664Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "outputs": [
    {
     "data": {
      "text/plain": "'Output #9: 2.67'"
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r = 8 / float(3)\n",
    "'Output #9: {0:.2f}'.format(r)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:39.901550Z",
     "end_time": "2024-02-07T17:08:40.747664Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "outputs": [
    {
     "data": {
      "text/plain": "'Output #10: 2.6667'"
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'Output #10: {0:.4f}'.format(8.0 / 3)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:39.905574Z",
     "end_time": "2024-02-07T17:08:40.747664Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "outputs": [
    {
     "data": {
      "text/plain": "'Output #11: 20.0855'"
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from math import exp, log, sqrt\n",
    "\n",
    "'Output #11: {0:.4f}'.format(exp(3))"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:39.911553Z",
     "end_time": "2024-02-07T17:08:40.748675Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "outputs": [
    {
     "data": {
      "text/plain": "'Output #12: 1.39'"
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'Output #12: {0:.2f}'.format(log(4))"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:39.916794Z",
     "end_time": "2024-02-07T17:08:40.748675Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "outputs": [
    {
     "data": {
      "text/plain": "'Output #13: 9.0'"
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'Output #13: {0:.1f}'.format(sqrt(81))"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:39.922574Z",
     "end_time": "2024-02-07T17:08:40.748675Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "outputs": [
    {
     "data": {
      "text/plain": "\"Output #14: I'm enjoying learning Python.\""
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'Output #14: {0:s}'.format('I\\'m enjoying learning Python.')"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:39.932576Z",
     "end_time": "2024-02-07T17:08:40.748675Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "outputs": [
    {
     "data": {
      "text/plain": "'Output #15: This is a long string. Without the backslash it would run off of the page on the right in the editor and be very difficult to read and edit. By using the backslash you can split the long string into smaller string on separate lines so that whole string is easy to view in the text editor.'"
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'Output #15: {0:s}'.format(\"This is a long string. Without the backslash\\\n",
    " it would run off of the page on the right in the editor and be very\\\n",
    " difficult to read and edit. By using the backslash you can split the long\\\n",
    " string into smaller string on separate lines so that whole string is easy\\\n",
    " to view in the text editor.\")"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:39.936394Z",
     "end_time": "2024-02-07T17:08:40.748675Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "outputs": [
    {
     "data": {
      "text/plain": "'Output #16: You can use triple single quotes\\nfor multi-line comment strings.'"
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'Output #16: {0:s}'.format('''You can use triple single quotes\n",
    "for multi-line comment strings.''')"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:39.942176Z",
     "end_time": "2024-02-07T17:08:40.748675Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "outputs": [
    {
     "data": {
      "text/plain": "'Output #17: You can also use triple double quotes\\nfor multi-line comment strings.'"
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'Output #17: {0:s}'.format(\"\"\"You can also use triple double quotes\n",
    "for multi-line comment strings.\"\"\")"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:39.947220Z",
     "end_time": "2024-02-07T17:08:40.748675Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "outputs": [
    {
     "data": {
      "text/plain": "'Output #18: This is a short string.'"
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "string1 = 'This is a '\n",
    "string2 = 'short string.'\n",
    "sentence = string1 + string2\n",
    "'Output #18: {0:s}'.format(sentence)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:39.954632Z",
     "end_time": "2024-02-07T17:08:40.748675Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "outputs": [
    {
     "data": {
      "text/plain": "'Output #19: She is very very very very beautiful.'"
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'Output #19: {0:s} {1:s}{2:s}'.format('She is', 'very ' * 4, 'beautiful.')"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:39.958704Z",
     "end_time": "2024-02-07T17:08:40.749665Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "outputs": [
    {
     "data": {
      "text/plain": "'Output #20: 23'"
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "m = len(sentence)\n",
    "'Output #20: {0:d}'.format(m)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:39.965888Z",
     "end_time": "2024-02-07T17:08:40.749665Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "outputs": [
    {
     "data": {
      "text/plain": "\"Output #21: ['My', 'deliverable', 'is', 'due', 'in', 'May']\""
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "string1 = 'My deliverable is due in May'\n",
    "string1_list1 = string1.split()\n",
    "string1_list2 = string1.split(' ', 2)\n",
    "'Output #21: {0}'.format(string1_list1)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:39.969069Z",
     "end_time": "2024-02-07T17:08:40.749665Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "outputs": [
    {
     "data": {
      "text/plain": "'Output #22: FIRST PIECE:My SECOND PIECE:deliverable THIRED PIECE:is due in May'"
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'Output #22: FIRST PIECE:{0} SECOND PIECE:{1} THIRED PIECE:{2}'.format(string1_list2[0], string1_list2[1],\n",
    "                                                                       string1_list2[2])"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:39.975639Z",
     "end_time": "2024-02-07T17:08:40.749665Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "outputs": [
    {
     "data": {
      "text/plain": "\"Output #23: ['Your', 'deliverable', 'is', 'due', 'in', 'June']\""
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "string2 = 'Your,deliverable,is,due,in,June'\n",
    "string2_list = string2.split(',')\n",
    "'Output #23: {0}'.format(string2_list)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:39.982829Z",
     "end_time": "2024-02-07T17:08:40.749665Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "outputs": [
    {
     "data": {
      "text/plain": "'Output #24: deliverable June June'"
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'Output #24: {0} {1} {2}'.format(string2_list[1], string2_list[5], string2_list[-1])"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:39.990280Z",
     "end_time": "2024-02-07T17:08:40.749665Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "outputs": [
    {
     "data": {
      "text/plain": "'Output #25: Your,deliverable,is,due,in,June'"
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'Output #25: {0}'.format(','.join(string2_list))"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:39.993670Z",
     "end_time": "2024-02-07T17:08:40.749665Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "outputs": [
    {
     "data": {
      "text/plain": "'Output #26: string3:  Remove unwanted characters    from this string.\\t\\t      \\n'"
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "string3 = ' Remove unwanted characters    from this string.\\t\\t      \\n'\n",
    "'Output #26: string3: {0:s}'.format(string3)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:40.001670Z",
     "end_time": "2024-02-07T17:08:40.749665Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "outputs": [
    {
     "data": {
      "text/plain": "'Output #27: lstrip: Remove unwanted characters    from this string.\\t\\t      \\n'"
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "string3_lstrip = string3.lstrip()\n",
    "'Output #27: lstrip: {0:s}'.format(string3_lstrip)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:40.006656Z",
     "end_time": "2024-02-07T17:08:40.750676Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "outputs": [
    {
     "data": {
      "text/plain": "'Output #28: rstrip:  Remove unwanted characters    from this string.'"
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "string3_rstrip = string3.rstrip()\n",
    "'Output #28: rstrip: {0:s}'.format(string3_rstrip)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:40.014180Z",
     "end_time": "2024-02-07T17:08:40.750676Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "outputs": [
    {
     "data": {
      "text/plain": "'Output #29: strip: Remove unwanted characters    from this string.'"
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "string3_strip = string3.strip()\n",
    "'Output #29: strip: {0:s}'.format(string3_strip)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:40.019362Z",
     "end_time": "2024-02-07T17:08:40.806677Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "outputs": [
    {
     "data": {
      "text/plain": "\"Output #30: $$Here's another string that has unwanted characters.__---++\""
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "string4 = \"$$Here's another string that has unwanted characters.__---++\"\n",
    "'Output #30: {0:s}'.format(string4)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:40.027122Z",
     "end_time": "2024-02-07T17:08:40.807685Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "outputs": [
    {
     "data": {
      "text/plain": "'Output #31: The unwanted characters have been removed.'"
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "string4 = '$$The unwanted characters have been removed.__---++'\n",
    "string4_strip = string4.strip('$_-+')\n",
    "'Output #31: {0:s}'.format(string4_strip)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:40.032636Z",
     "end_time": "2024-02-07T17:08:40.807685Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "outputs": [
    {
     "data": {
      "text/plain": "\"Output #32 (with !@!): Let's!@!replace!@!the!@!spaces!@!in!@!this!@!sentence!@!with!@!other!@!characters.\""
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "string5 = \"Let's replace the spaces in this sentence with other characters.\"\n",
    "string5_replace = string5.replace(' ', '!@!')\n",
    "'Output #32 (with !@!): {0:s}'.format(string5_replace)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:40.039324Z",
     "end_time": "2024-02-07T17:08:40.807685Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "outputs": [
    {
     "data": {
      "text/plain": "\"Output #33 (with commas): Let's,replace,the,spaces,in,this,sentence,with,other,characters.\""
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "string5_replace = string5.replace(' ', ',')\n",
    "'Output #33 (with commas): {0:s}'.format(string5_replace)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:40.042582Z",
     "end_time": "2024-02-07T17:08:40.808684Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "outputs": [
    {
     "data": {
      "text/plain": "\"Output #34: here's what happens when you use lower.\""
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "string6 = \"Here's WHAT Happens WHEN You Use lower.\"\n",
    "'Output #34: {0:s}'.format(string6.lower())"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:40.050440Z",
     "end_time": "2024-02-07T17:08:40.808684Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "outputs": [
    {
     "data": {
      "text/plain": "\"Output #35: HERE'S WHAT HAPPENS WHEN YOU USE UPPER.\""
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "string7 = \"Here's what Happens when You Use UPPER.\"\n",
    "'Output #35: {0:s}'.format(string7.upper())"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:40.056379Z",
     "end_time": "2024-02-07T17:08:40.808684Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "outputs": [
    {
     "data": {
      "text/plain": "\"Output #36: Here's what happens when you use capitalize.\""
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "string5 = \"here's WHAT Happens WHEN you use Capitalize.\"\n",
    "'Output #36: {0:s}'.format(string5.capitalize())"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:40.060518Z",
     "end_time": "2024-02-07T17:08:40.808684Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Output #37 (on each word):\n",
      "Here's\n",
      "What\n",
      "Happens\n",
      "When\n",
      "You\n",
      "Use\n",
      "Capitalize.\n"
     ]
    }
   ],
   "source": [
    "string5_list = string5.split()\n",
    "print('Output #37 (on each word):')\n",
    "for word in string5_list:\n",
    "    print('{0:s}'.format(word.capitalize()))"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:40.067248Z",
     "end_time": "2024-02-07T17:08:40.808684Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "outputs": [
    {
     "data": {
      "text/plain": "'Output #38: 2'"
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import re\n",
    "\n",
    "# 计算字符串模式出现的次数\n",
    "string = 'The quick brown fox jumps over the lazy dog.'\n",
    "string_list = string.split()\n",
    "pattern = re.compile(r'The', re.I)\n",
    "count = 0\n",
    "for word in string_list:\n",
    "    if pattern.search(word):\n",
    "        count += 1\n",
    "'Output #38: {0:d}'.format(count)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:40.074333Z",
     "end_time": "2024-02-07T17:08:40.808684Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Output #39:\n",
      "The\n",
      "the\n"
     ]
    }
   ],
   "source": [
    "# 在字符串中每次找到模式时将其打印出来\n",
    "string = 'The quick brown fox jumps over the lazy dog.'\n",
    "string_list = string.split()\n",
    "pattern = re.compile(r'(?P<match_word>The)', re.I)\n",
    "pattern\n",
    "print('Output #39:')\n",
    "for word in string_list:\n",
    "    if pattern.search(word):\n",
    "        print('{:s}'.format(pattern.search(word).group('match_word')))"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:40.080405Z",
     "end_time": "2024-02-07T17:08:40.809678Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "outputs": [
    {
     "data": {
      "text/plain": "'Output #40: a quick brown fox jumps over a lazy dog.'"
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#使用字母“a”替换字符串中的单词“the”\n",
    "string = 'The quick brown fox jumps over the lazy dog.'\n",
    "string_to_find = r\"The\"\n",
    "pattern = re.compile(string_to_find, re.I)\n",
    "'Output #40: {:s}'.format(pattern.sub('a', string))"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:40.088752Z",
     "end_time": "2024-02-07T17:08:40.809678Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "outputs": [
    {
     "data": {
      "text/plain": "'Output #41: today: 2024-02-07'"
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from datetime import date, datetime, timedelta\n",
    "\n",
    "#打印出今天的日期形式，以及年月日\n",
    "today = date.today()\n",
    "'Output #41: today: {0!s}'.format(today)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:40.100027Z",
     "end_time": "2024-02-07T17:08:40.809678Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "outputs": [
    {
     "data": {
      "text/plain": "'Output #42: 2024'"
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'Output #42: {0!s}'.format(today.year)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:40.104027Z",
     "end_time": "2024-02-07T17:08:40.809678Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "outputs": [
    {
     "data": {
      "text/plain": "'Output #43: 2'"
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'Output #43: {0!s}'.format(today.month)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:40.109554Z",
     "end_time": "2024-02-07T17:08:40.809678Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "outputs": [
    {
     "data": {
      "text/plain": "'Output #44: 7'"
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'Output #44: {0!s}'.format(today.day)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:40.116939Z",
     "end_time": "2024-02-07T17:08:40.809678Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "outputs": [
    {
     "data": {
      "text/plain": "'Output #45: 2024-02-07 17:08:40.122833'"
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "current_datetime = datetime.today()\n",
    "'Output #45: {0!s}'.format(current_datetime)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:40.122833Z",
     "end_time": "2024-02-07T17:08:40.809678Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "outputs": [
    {
     "data": {
      "text/plain": "'Output #46: yesterday: 2024-02-06'"
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 使用timedelta计算一个新日期\n",
    "one_day = timedelta(days=-1)\n",
    "yesterday = today + one_day\n",
    "'Output #46: yesterday: {0!s}'.format(yesterday)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:40.130288Z",
     "end_time": "2024-02-07T17:08:40.809678Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "outputs": [
    {
     "data": {
      "text/plain": "'Output #47: -1 57600'"
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "eight_hours = timedelta(hours=-8)\n",
    "'Output #47: {0!s} {1!s}'.format(eight_hours.days, eight_hours.seconds)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:40.133805Z",
     "end_time": "2024-02-07T17:08:40.809678Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "outputs": [
    {
     "data": {
      "text/plain": "'Output #48: 1 day, 0:00:00'"
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 计算两个日期之间的天数\n",
    "date_diff = today - yesterday\n",
    "'Output #48: {0!s}'.format(date_diff)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:40.139954Z",
     "end_time": "2024-02-07T17:08:40.810678Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "outputs": [
    {
     "data": {
      "text/plain": "'Output #49: 1'"
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'Output #49: {0!s}'.format(str(date_diff).split()[0])"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:40.146062Z",
     "end_time": "2024-02-07T17:08:40.810678Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "outputs": [
    {
     "data": {
      "text/plain": "'Output #50: 02/07/2024'"
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'Output #50: {:s}'.format(today.strftime('%m/%d/%Y'))"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:40.152809Z",
     "end_time": "2024-02-07T17:08:40.810678Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "outputs": [
    {
     "data": {
      "text/plain": "'Output #51: Feb 07, 2024'"
     },
     "execution_count": 51,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'Output #51: {:s}'.format(today.strftime('%b %d, %Y'))"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:40.157126Z",
     "end_time": "2024-02-07T17:08:40.810678Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "outputs": [
    {
     "data": {
      "text/plain": "'Output #52: 2024-02-07'"
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'Output #52: {:s}'.format(today.strftime('%Y-%m-%d'))"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:40.163053Z",
     "end_time": "2024-02-07T17:08:40.810678Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "outputs": [
    {
     "data": {
      "text/plain": "'Output #53: February 07, 2024'"
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'Output #53: {:s}'.format(today.strftime('%B %d, %Y'))"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:40.170135Z",
     "end_time": "2024-02-07T17:08:40.810678Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "outputs": [
    {
     "data": {
      "text/plain": "'Output #54: 2024-02-07 00:00:00'"
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "date1 = today.strftime('%m/%d/%Y')\n",
    "date2 = today.strftime('%b %d, %Y')\n",
    "date3 = today.strftime('%Y-%m-%d')\n",
    "date4 = today.strftime('%B %d, %Y')\n",
    "'Output #54: {!s}'.format(datetime.strptime(date1, '%m/%d/%Y'))"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:40.175107Z",
     "end_time": "2024-02-07T17:08:40.810678Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "outputs": [
    {
     "data": {
      "text/plain": "'Output #55: 2024-02-07 00:00:00'"
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'Output #55: {!s}'.format(datetime.strptime(date2, '%b %d, %Y'))"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:40.183100Z",
     "end_time": "2024-02-07T17:08:40.810678Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "outputs": [
    {
     "data": {
      "text/plain": "'Output #56: 2024-02-07'"
     },
     "execution_count": 56,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'Output #56: {!s}'.format(datetime.date(datetime.strptime(date3, '%Y-%m-%d')))"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:40.190537Z",
     "end_time": "2024-02-07T17:08:40.810678Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "outputs": [
    {
     "data": {
      "text/plain": "'Output #57: 2024-02-07'"
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'Output #57: {!s}'.format(datetime.date(datetime.strptime(date4, '%B %d, %Y')))"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:40.196434Z",
     "end_time": "2024-02-07T17:08:40.811690Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "outputs": [
    {
     "data": {
      "text/plain": "'Output #58: [1, 2, 3]'"
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a_list = [1, 2, 3]\n",
    "'Output #58: {}'.format(a_list)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:40.203481Z",
     "end_time": "2024-02-07T17:08:40.811690Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "outputs": [
    {
     "data": {
      "text/plain": "'Output #59: a_list has 3 elements.'"
     },
     "execution_count": 59,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'Output #59: a_list has {} elements.'.format(len(a_list))"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:40.208743Z",
     "end_time": "2024-02-07T17:08:40.811690Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "outputs": [
    {
     "data": {
      "text/plain": "'Output #60: the maximum value in a_list is 3.'"
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'Output #60: the maximum value in a_list is {}.'.format(max(a_list))"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:40.216256Z",
     "end_time": "2024-02-07T17:08:40.811690Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "outputs": [
    {
     "data": {
      "text/plain": "'Output #61: the minimum value in a_list is 1.'"
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'Output #61: the minimum value in a_list is {}.'.format(min(a_list))"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:40.222570Z",
     "end_time": "2024-02-07T17:08:40.811690Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "outputs": [
    {
     "data": {
      "text/plain": "\"Output #62: ['printer', 5, ['star', 'circle', 9]]\""
     },
     "execution_count": 62,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "another_list = ['printer', 5, ['star', 'circle', 9]]\n",
    "'Output #62: {}'.format(another_list)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:40.225902Z",
     "end_time": "2024-02-07T17:08:40.811690Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "outputs": [
    {
     "data": {
      "text/plain": "'Output #63: another_list also has 3 elements.'"
     },
     "execution_count": 63,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'Output #63: another_list also has {} elements.'.format(len(another_list))"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:40.231407Z",
     "end_time": "2024-02-07T17:08:40.811690Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "outputs": [
    {
     "data": {
      "text/plain": "'Output #64: 5 is in another_list 1 time.'"
     },
     "execution_count": 64,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'Output #64: 5 is in another_list {} time.'.format(another_list.count(5))"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:40.239753Z",
     "end_time": "2024-02-07T17:08:40.811690Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "outputs": [
    {
     "data": {
      "text/plain": "'Output #65: 1'"
     },
     "execution_count": 65,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'Output #65: {}'.format(a_list[0])"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:40.244099Z",
     "end_time": "2024-02-07T17:08:40.811690Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "outputs": [
    {
     "data": {
      "text/plain": "'Output #66: 2'"
     },
     "execution_count": 66,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'Output #66: {}'.format(a_list[1])"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:40.248508Z",
     "end_time": "2024-02-07T17:08:40.812690Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "outputs": [
    {
     "data": {
      "text/plain": "'Output #67: 3'"
     },
     "execution_count": 67,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'Output #67: {}'.format(a_list[2])"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:40.254567Z",
     "end_time": "2024-02-07T17:08:40.812690Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "outputs": [
    {
     "data": {
      "text/plain": "'Output #68: 3'"
     },
     "execution_count": 68,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'Output #68: {}'.format(a_list[-1])"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:40.261584Z",
     "end_time": "2024-02-07T17:08:40.812690Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "outputs": [
    {
     "data": {
      "text/plain": "'Output #69: 2'"
     },
     "execution_count": 69,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'Output #69: {}'.format(a_list[-2])"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:40.266584Z",
     "end_time": "2024-02-07T17:08:40.812690Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "outputs": [
    {
     "data": {
      "text/plain": "'Output #70: 1'"
     },
     "execution_count": 70,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'Output #70: {}'.format(a_list[-3])"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:40.272291Z",
     "end_time": "2024-02-07T17:08:40.812690Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "outputs": [
    {
     "data": {
      "text/plain": "\"Output #71: ['star', 'circle', 9]\""
     },
     "execution_count": 71,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'Output #71: {}'.format(another_list[2])"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:40.280330Z",
     "end_time": "2024-02-07T17:08:40.812690Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "outputs": [
    {
     "data": {
      "text/plain": "\"Output #72: ['star', 'circle', 9]\""
     },
     "execution_count": 72,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'Output #72: {}'.format(another_list[-1])"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:40.284328Z",
     "end_time": "2024-02-07T17:08:40.812690Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "outputs": [
    {
     "data": {
      "text/plain": "'Output #73: [1, 2]'"
     },
     "execution_count": 73,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'Output #73: {}'.format(a_list[0:2])"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:40.289803Z",
     "end_time": "2024-02-07T17:08:40.813685Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "outputs": [
    {
     "data": {
      "text/plain": "\"Output #74: ['printer', 5]\""
     },
     "execution_count": 74,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'Output #74: {}'.format(another_list[:2])"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:40.295110Z",
     "end_time": "2024-02-07T17:08:40.813685Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "outputs": [
    {
     "data": {
      "text/plain": "'Output #75: [2, 3]'"
     },
     "execution_count": 75,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'Output #75: {}'.format(a_list[1:3])"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:40.299912Z",
     "end_time": "2024-02-07T17:08:40.813685Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "outputs": [
    {
     "data": {
      "text/plain": "\"Output #76: [5, ['star', 'circle', 9]]\""
     },
     "execution_count": 76,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'Output #76: {}'.format(another_list[1:])"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:40.306300Z",
     "end_time": "2024-02-07T17:08:40.813685Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 77,
   "outputs": [
    {
     "data": {
      "text/plain": "'Output #77: [1, 2, 3]'"
     },
     "execution_count": 77,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a_new_list = a_list[:]\n",
    "'Output #77: {}'.format(a_new_list)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:40.311399Z",
     "end_time": "2024-02-07T17:08:40.813685Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 78,
   "outputs": [
    {
     "data": {
      "text/plain": "\"Output #78: [1, 2, 3, 'printer', 5, ['star', 'circle', 9]]\""
     },
     "execution_count": 78,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a_long_list = a_list + another_list\n",
    "'Output #78: {}'.format(a_long_list)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:40.318015Z",
     "end_time": "2024-02-07T17:08:40.813685Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "outputs": [
    {
     "data": {
      "text/plain": "'Output # 79: True'"
     },
     "execution_count": 79,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = 2 in a_list\n",
    "'Output # 79: {}'.format(a)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:40.322703Z",
     "end_time": "2024-02-07T17:08:40.813685Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Output #80: 2 is in [1, 2, 3].\n"
     ]
    }
   ],
   "source": [
    "if 2 in a_list:\n",
    "    print('Output #80: 2 is in {}.'.format(a_list))"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:40.329595Z",
     "end_time": "2024-02-07T17:08:40.813685Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "outputs": [
    {
     "data": {
      "text/plain": "'Output #81: True'"
     },
     "execution_count": 81,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "b = 6 not in a_list\n",
    "'Output #81: {}'.format(b)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:40.334106Z",
     "end_time": "2024-02-07T17:08:40.813685Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 82,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Output #82: 6 is not in [1, 2, 3].\n"
     ]
    }
   ],
   "source": [
    "if 6 not in a_list:\n",
    "    print('Output #82: 6 is not in {}.'.format(a_list))"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:40.341103Z",
     "end_time": "2024-02-07T17:08:40.814686Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 83,
   "outputs": [
    {
     "data": {
      "text/plain": "'Output #83: [1, 2, 3, 4, 5, 6]'"
     },
     "execution_count": 83,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a_list.append(4)\n",
    "a_list.append(5)\n",
    "a_list.append(6)\n",
    "'Output #83: {}'.format(a_list)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:40.346262Z",
     "end_time": "2024-02-07T17:08:40.815686Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 84,
   "outputs": [
    {
     "data": {
      "text/plain": "'Output #84: [1, 2, 3, 4, 6]'"
     },
     "execution_count": 84,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a_list.remove(5)\n",
    "'Output #84: {}'.format(a_list)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:40.349942Z",
     "end_time": "2024-02-07T17:08:40.815686Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 85,
   "outputs": [
    {
     "data": {
      "text/plain": "'Output #85: [1, 2, 3]'"
     },
     "execution_count": 85,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a_list.pop()\n",
    "a_list.pop()\n",
    "'Output #85: {}'.format(a_list)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:40.357122Z",
     "end_time": "2024-02-07T17:08:40.815686Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "outputs": [
    {
     "data": {
      "text/plain": "'Output #86: [3, 2, 1]'"
     },
     "execution_count": 86,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a_list.reverse()\n",
    "'Output #86: {}'.format(a_list)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:40.362125Z",
     "end_time": "2024-02-07T17:08:40.816686Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 87,
   "outputs": [
    {
     "data": {
      "text/plain": "'Output #87: [1, 2, 3]'"
     },
     "execution_count": 87,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a_list.reverse()\n",
    "'Output #87: {}'.format(a_list)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:40.369481Z",
     "end_time": "2024-02-07T17:08:40.816686Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 88,
   "outputs": [
    {
     "data": {
      "text/plain": "'Output #88: [3, 5, 1, 7, 2, 8, 4, 9, 0, 6]'"
     },
     "execution_count": 88,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "unordered_list = [3, 5, 1, 7, 2, 8, 4, 9, 0, 6]\n",
    "'Output #88: {}'.format(unordered_list)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:40.374047Z",
     "end_time": "2024-02-07T17:08:40.816686Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 89,
   "outputs": [
    {
     "data": {
      "text/plain": "'Output #89: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]'"
     },
     "execution_count": 89,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list_copy = unordered_list[:]\n",
    "list_copy.sort()\n",
    "'Output #89: {}'.format(list_copy)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:40.381604Z",
     "end_time": "2024-02-07T17:08:40.817686Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 90,
   "outputs": [
    {
     "data": {
      "text/plain": "'Output #90: [3, 5, 1, 7, 2, 8, 4, 9, 0, 6]'"
     },
     "execution_count": 90,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'Output #90: {}'.format(unordered_list)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:40.388851Z",
     "end_time": "2024-02-07T17:08:40.817686Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 91,
   "outputs": [
    {
     "data": {
      "text/plain": "'Output #91: [[4, 3, 2, 1], [2, 4, 1, 3], [1, 2, 3, 4]]'"
     },
     "execution_count": 91,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "my_lists = [[1, 2, 3, 4], [4, 3, 2, 1], [2, 4, 1, 3]]\n",
    "my_lists_sorted_by_index_3 = sorted(my_lists, key=lambda index_value: index_value[3])\n",
    "'Output #91: {}'.format(my_lists_sorted_by_index_3)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:40.392849Z",
     "end_time": "2024-02-07T17:08:40.817686Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 92,
   "outputs": [
    {
     "data": {
      "text/plain": "'Output #92: [[461, 1, 1, 290], [578, 1, 1, 290], [22, 6, 6, 444], [123, 2, 2, 444], [236, 5, 5, 678], [354, 4, 4, 678]]'"
     },
     "execution_count": 92,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from operator import itemgetter\n",
    "\n",
    "my_lists = [[123, 2, 2, 444], [22, 6, 6, 444], [354, 4, 4, 678], [236, 5, 5, 678], [578, 1, 1, 290], [461, 1, 1, 290]]\n",
    "my_lists_sorted_by_index_3_and_0 = sorted(my_lists, key=itemgetter(3, 0))\n",
    "'Output #92: {}'.format(my_lists_sorted_by_index_3_and_0)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:40.399295Z",
     "end_time": "2024-02-07T17:08:40.819676Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 93,
   "outputs": [
    {
     "data": {
      "text/plain": "\"Output #93: ('x', 'y', 'z')\""
     },
     "execution_count": 93,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "my_tuple = ('x', 'y', 'z')\n",
    "'Output #93: {}'.format(my_tuple)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:40.405113Z",
     "end_time": "2024-02-07T17:08:40.820688Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 94,
   "outputs": [
    {
     "data": {
      "text/plain": "'Output #94: my_tuple has 3 elements'"
     },
     "execution_count": 94,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'Output #94: my_tuple has {} elements'.format(len(my_tuple))"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:40.409576Z",
     "end_time": "2024-02-07T17:08:40.820688Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 95,
   "outputs": [
    {
     "data": {
      "text/plain": "'Output #95: y'"
     },
     "execution_count": 95,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'Output #95: {}'.format(my_tuple[1])"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:40.416473Z",
     "end_time": "2024-02-07T17:08:40.820688Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 96,
   "outputs": [
    {
     "data": {
      "text/plain": "\"Output #96: ('x', 'y', 'z', 'x', 'y', 'z')\""
     },
     "execution_count": 96,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "longer_tuple = my_tuple + my_tuple\n",
    "'Output #96: {}'.format(longer_tuple)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:40.423419Z",
     "end_time": "2024-02-07T17:08:40.820688Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 97,
   "outputs": [
    {
     "data": {
      "text/plain": "'Output #97: x y z'"
     },
     "execution_count": 97,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "one, two, three = my_tuple\n",
    "'Output #97: {0} {1} {2}'.format(one, two, three)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:40.429770Z",
     "end_time": "2024-02-07T17:08:40.820688Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 98,
   "outputs": [
    {
     "data": {
      "text/plain": "'Output #98: red robin'"
     },
     "execution_count": 98,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "var1 = 'red'\n",
    "var2 = 'robin'\n",
    "'Output #98: {} {}'.format(var1, var2)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:40.437654Z",
     "end_time": "2024-02-07T17:08:40.821682Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 99,
   "outputs": [
    {
     "data": {
      "text/plain": "'Output #99: robin red'"
     },
     "execution_count": 99,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "var1, var2 = var2, var1\n",
    "'Output #99: {} {}'.format(var1, var2)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:40.441689Z",
     "end_time": "2024-02-07T17:08:40.822684Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 100,
   "outputs": [
    {
     "data": {
      "text/plain": "'Output #100: (1, 2, 3)'"
     },
     "execution_count": 100,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "my_list = [1, 2, 3]\n",
    "my_tuple = ('x', 'y', 'z')\n",
    "'Output #100: {}'.format(tuple(my_list))"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:40.449597Z",
     "end_time": "2024-02-07T17:08:40.822684Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 101,
   "outputs": [
    {
     "data": {
      "text/plain": "\"Output #101: ['x', 'y', 'z']\""
     },
     "execution_count": 101,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'Output #101: {}'.format(list(my_tuple))"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:40.456809Z",
     "end_time": "2024-02-07T17:08:40.822684Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 102,
   "outputs": [
    {
     "data": {
      "text/plain": "\"Output #102: {'one': 1, 'two': 2, 'three': 3}\""
     },
     "execution_count": 102,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "empty_dict = {}\n",
    "a_dict = {'one': 1, 'two': 2, 'three': 3}\n",
    "'Output #102: {}'.format(a_dict)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:40.463714Z",
     "end_time": "2024-02-07T17:08:40.822684Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 103,
   "outputs": [
    {
     "data": {
      "text/plain": "'Output #103: a_dict has 3 elements'"
     },
     "execution_count": 103,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'Output #103: a_dict has {!s} elements'.format(len(a_dict))"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:40.468960Z",
     "end_time": "2024-02-07T17:08:40.822684Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 104,
   "outputs": [
    {
     "data": {
      "text/plain": "\"Output #104: {'x': 'printer', 'y': 5, 'z': ['star', 'circle', 9]}\""
     },
     "execution_count": 104,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "another_dict = {'x': 'printer', 'y': 5, 'z': ['star', 'circle', 9]}\n",
    "'Output #104: {}'.format(another_dict)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:40.475031Z",
     "end_time": "2024-02-07T17:08:40.823676Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 105,
   "outputs": [
    {
     "data": {
      "text/plain": "'Output #105: another_dict also has 3 elements'"
     },
     "execution_count": 105,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'Output #105: another_dict also has {!s} elements'.format(len(another_dict))"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:40.480705Z",
     "end_time": "2024-02-07T17:08:40.823676Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 106,
   "outputs": [
    {
     "data": {
      "text/plain": "'Output #106: 2'"
     },
     "execution_count": 106,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'Output #106: {}'.format(a_dict['two'])"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:40.488238Z",
     "end_time": "2024-02-07T17:08:40.823676Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 107,
   "outputs": [
    {
     "data": {
      "text/plain": "\"Output #107: ['star', 'circle', 9]\""
     },
     "execution_count": 107,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'Output #107: {}'.format(another_dict['z'])"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:40.491913Z",
     "end_time": "2024-02-07T17:08:40.823676Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 108,
   "outputs": [
    {
     "data": {
      "text/plain": "\"Output #108: {'one': 1, 'two': 2, 'three': 3}\""
     },
     "execution_count": 108,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a_new_dict = a_dict.copy()\n",
    "'Output #108: {}'.format(a_new_dict)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:40.499207Z",
     "end_time": "2024-02-07T17:08:40.823676Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 108,
   "outputs": [],
   "source": [],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-02-07T17:08:40.504606Z",
     "end_time": "2024-02-07T17:08:40.823676Z"
    }
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
